"""
@FileName：7生成日期.py
@Author：lmz
@Time：2021/5/19 22:24
设计一个日期的类，这个类包含年、月、日三个属性，通过输入设置当前的年、月、日。
同时，这个类还有一些静态方法，比如，获取今天的日期，
明天的日期，下周（七天后）的日期，上周（七天前）的日期。
另外，日期要按照“2018年10月23日”这种格式打印输出。
"""


def tianshu(nian, yue, ri, change):
    yue_ri = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    sumday = 0
    sumday = sum(yue_ri[:(yue)]) + ri
    sumday += change

    if nian % 4 == 0 and yue > 2:
        if nian % 100 != 0:
            sumday = sumday + 1
        if nian % 100 == 0 and nian % 400 == 0:
            sumday = sumday + 1

    for i, item in enumerate(yue_ri):
        if sum(yue_ri[:i]) < sumday and sum(yue_ri[:i + 1]) > sumday:

            if nian % 4 == 0 and yue > 2:
                if nian % 100 != 0:
                    sumday = sumday - 1
                if nian % 100 == 0 and nian % 400 == 0:
                    sumday = sumday - 1

            yue = i
            ri = sumday - sum(yue_ri[:i])
    return nian, yue, ri


class riqi():
    def __init__(self, nian, yue, ri, renyi):
        self.nian = nian
        self.yue = yue
        self.ri = ri
        self.renyi = renyi

    def today(self):
        print(f"{self.nian}年{self.yue}月{self.ri}日")

    def nextday(self):
        nian, yue, ri = tianshu(self.nian, self.yue, self.ri, 1)
        print(f"{nian}年{yue}月{ri}日")

    def lastday(self):
        nian, yue, ri = tianshu(self.nian, self.yue, self.ri, -1)
        print(f"{nian}年{yue}月{ri}日")

    @staticmethod
    def lastsevendays(nian, yue, ri):
        nian, yue, ri = tianshu(nian, yue, ri, -7)
        print(f"{nian}年{yue}月{ri}日")

    @staticmethod
    def nextsevendays(nian, yue, ri):
        nian, yue, ri = tianshu(nian, yue, ri, 7)
        print(f"{nian}年{yue}月{ri}日")

    def zidingyi(self, nian, yue, ri, renyi):
        nian, yue, ri = tianshu(nian, yue, ri, renyi)
        print(f"{nian}年{yue}月{ri}日")


d1 = riqi(2020, 8, 4, -10)
d1.today()
d1.nextday()
d1.lastday()
d1.lastsevendays(2020, 8, 4)
d1.nextsevendays(2020, 8, 4)
d1.zidingyi(2020, 8, 4, -10)
